package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherApi;
import com.xuecheng.api.content.teacher.CourseTeacherDTO;
import com.xuecheng.api.content.teacher.CourseTeacherVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeacherCourse;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author xuan
 */
@Slf4j
@RestController
//@RequestMapping("courseTeacher")
public class CourseTeacherController implements CourseTeacherApi {

    @Autowired
    private CourseTeacherService  courseTeacherService;

    @GetMapping("/courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> selectAll(@PathVariable Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        List<CourseTeacherDTO> result = courseTeacherService.selectAll(courseBaseId, companyId);
        return result;

    }

    @PostMapping("/courseTeacher")
    public CourseTeacherDTO createOrModifyCourseTeacher(@RequestBody CourseTeacherVO vo) {
        CourseTeacherDTO dto = TeacherCourse.INSTANCE.vo2Dto(vo);
        Long companyId = SecurityUtil.getCompanyId();
        CourseTeacherDTO orModifyCourseTeacher = courseTeacherService.createOrModifyCourseTeacher(dto, companyId);
        return orModifyCourseTeacher;
    }

    @DeleteMapping("courseTeacher/course/{courseBase}/{courseTeacherId}")
    public void removeCourseTeacher(@PathVariable Long courseBase,@PathVariable Long courseTeacherId) {
        Long companyId = SecurityUtil.getCompanyId();
        courseTeacherService.removeCourseTeacher(courseBase,courseTeacherId,companyId);
    }


}
